package com.wbihua.grpc.demo;

import com.wbihua.grpc.demo.entity.User;
import com.wbihua.grpc.demo.spring.annotation.GrpcService;
import com.wbihua.grpc.demo.spring.annotation.GrpcServiceScan;
import com.wbihua.grpc.demo.spring.annotation.MapperScan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Map;

@SpringBootApplication
@Slf4j
@GrpcServiceScan(basePackages = "com.wbihua.grpc.demo.service.impl", annotationClass = GrpcService.class)
@MapperScan(basePackages = "com.wbihua.grpc.demo.mapper")
public class SpringScanApplication  implements ApplicationRunner, ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringScanApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map<String, User> beanMap = applicationContext.getBeansOfType(User.class);
        beanMap.forEach((key,value)-> log.info("key: {} --> value: {}" ,key , value));
    }
}